home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 14
/
014.d81
/
pps #35
< prev
next >
Wrap
Text File
|
2022-08-26
|
5KB
|
191 lines
======================================
PEEKs, POKEs, & SYSes -- Part 35
By James Germany Weiler
and Alien Gardner
======================================
Bit-mapped graphics: how to do it
in BASIC.
- - - - - - - - - - - - - - - - - - -
A. Setting bit-mapped graphics mode.
This is easy. Set bit five of
of the VIC-II control register
(memory location 53265). This is
the bit that determines whether your
C-64 will display text or bit-mapped
graphics. You remember from part 32
that the value of bit five is 32.
However, we can't simply poke 32
into 53265 because the rest of the
bits in that memory location control
other functions of the VIC chip,
including the size and position of
the screen. Instead, we PEEK the
previous value out of 53265,
logically OR that value with 32,
and POKE the result back into 53265.
When you OR two bytes together,
whatever bits were set in either of
the original bytes will be set in
the resulting byte.
10 POKE 53265, PEEK(53625) OR 32
Then decide where in memory your
bit-map should start. This is most
often at memory location 8192. If
know how to do bank switching, you
can put it at 24576. Bank switching
is described on pages 101 and 102 of
the Commodore 64 Programmer's
Reference Guide. You can only use
banks 0 or 1 for high-resolution
bit-mapped graphics. Banks 2 and 3
have ROM where the bit-map would
go.
If you want to switch to bank 1,
POKE 56576,(PEEK(56576)AND 252)OR 2.
To return to bank 0, POKE 56576,
(PEEK(56576)AND 252) OR 3. One
advantage of bank-switching is
that you have more memory free for
your BASIC program.
We use OR again the same way we
did above so that we set bit three
without disturbing bits four through
seven of location 53272.
20 POKE 53272, PEEK(53272) OR 8
- - - - - - - - - - - - - - - - - - -
B. Clearing the bit-mapped screen.
This is easy, too, but time
consuming. Just poke zeros into
the 8000 bytes that make up one
bit-mapped screen. Of course, if
we had bank-switched, we would poke
the 8000 bytes starting at 24576.
30 FOR C = 8192 TO 8192+8000
40 POKE C, 0 : NEXT
- - - - - - - - - - - - - - - - - - -
C. Setting the color
This is a lot like clearing the
bit-mapped screen. We are limited
to two colors per block. Because
it is simpler to do so, we usually
choose to make all the blocks the
same colors.
The color information for a high
resolution bit-mapped screen is
stored in, of all places, the normal
text screen. Of course, if you
bank switch, that won't be the case.
Then, your color memory will be from
location 17408 through 18407,
exactly 16384 bytes (the size of
one bank) above the normal text
display. This is another advantage
of bank-switching -- you can put
color on your hi-res screen without
disturbing your text screen.
50 FOR C = 1024 TO 2023
60 POKE C, 5 : NEXT
This will produce a green screen
with black dots when we plot them.
Bits 0 through 3 of the color bytes
define the background color. Bits
4 through 7 define the color of
the dots we plot.
You must ensure that neither your
BASIC program nor its variables use
any part of the bit-mapped screen
or color memory. If your bit-map
is at 8192, you need to set MEMSIZ
to 8192. (POKE 55,0:POKE 56,32)
If you bank-switch, you can set
MEMSIZE to 17408, the beginning of
color memory. (POKE 55,0:POKE 56,68)
- - - - - - - - - - - - - - - - - - -
D. Plotting
This is by far the hairiest part
of hi-res bit-mapped graphics.
To plot a single point, we have to
determine which bit in which byte
of the 8000 bytes of the screen
corresponds to that point. There
are 320 dots across and 200 down.
They are numbered 0 to 319 and 0 to
199.
70 X = 50: Y = 120
80 L=8192 +INT(Y/8)*320 +INT(X/8)*8+(Y
AND7):POKE L,PEEK(L) OR2^(7-(X AND 7))
This will plot a point 50 pixels
from the left and 120 pixels down.
Don't worry about understanding
this formula. The only thing you
really need to know is to change
8192 to 24576 if you are bank-
switching. If you really want to
know what this is all about, try
wading through pages 121 to 127 in
the Commodore 64 Programmer's
Reference Guide.
- - - - - - - - - - - - - - - - - - -
E. Return to the text screen.
This is easy, too. Just undo what
you did in step A. First reset bit
five of the VIC-II control register
at 53265. In Boolean terms (AND,
OR, and NOT), 223 is the opposite of
32. That means that only bit 5 is
turned off. When you AND two bytes
together, whatever bits were set in
both the original bytes will be set
in the resulting byte. ANDing with
a byte that has only one bit off
guarantees that that one bit will be
reset in the result and that all the
other bits will be untouched.
100 POKE 53265, PEEK(53265) AND 223
And here we use the same technique
to undo our start-of-bit-map
selection.
110 POKE 53272, PEEK(53272) AND NOT 8
Finally, if we used bank-switching,
we have to re-select bank 0, the
normal bank.
POKE 56576,(PEEK(56576)AND 252)OR 3
-------< continued in Part 36 >-------